import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
 * 两数之和问题
 */
public class CodeTestB {

    public static int[] solve(int[] nums,int target){
        HashMap<Integer,Integer> map = new HashMap<>();
        for (int i=0;i<nums.length;i++){
            int complement = target - nums[i];
            if (map.containsKey(complement)){
                return new int[]{map.get(complement),i};
            }
            map.put(nums[i],i);
        }throw new IllegalArgumentException("Error");
    }

    //数据[2,7,11,15],target=9
    public static void main(String[] args) {
        int[] nums = new int[]{2,7,11,15};
        int[] result = CodeTestB.solve(nums,9);
        System.out.println(Arrays.toString(result));
    }
}
